<?php

namespace Xin\Robot;


use Xin\Capsule\Manager;
use Xin\Robot\Contracts\Factory;

/**
 * @mixin \Xin\Robot\Contracts\Robot
 */
class RobotManager extends Manager implements Factory
{

	/**
	 * @inheritDoc
	 */
	public function robot($name = null)
	{
		return $this->driver($name);
	}

	/**
	 * 创建企微机器人
	 * @param string $name
	 * @param array $config
	 * @return WeWorkRobot
	 */
	public function createWeworkDriver($name, array $config)
	{
		return new WeWorkRobot($config);
	}

	/**
	 * 创建钉钉机器人
	 * @param string $name
	 * @param array $config
	 * @return DingTalkRobot
	 */
	public function createDingTalkDriver($name, array $config): DingTalkRobot
	{
		return new DingTalkRobot($config, $name);
	}

    /**
     * 创建飞书机器人
     * @param string $name
     * @param array $config
     * @return FeiShuRobot
     */
    public function createFeiShuDriver($name, array $config): FeiShuRobot
    {
        return new FeiShuRobot($config);
    }

	/**
	 * @inerhitDoc
	 */
	public function getDefaultDriver()
	{
		return $this->getConfig('defaults.robot', 'default');
	}

	/**
	 * @inerhitDoc
	 */
	public function setDefaultDriver($name)
	{
		$this->setConfig('defaults.robot', $name);
	}

	/**
	 * @inerhitDoc
	 */
	public function getDriverConfig($name)
	{
		$key = 'robots';

		return $this->getConfig($name ? "{$key}.{$name}" : $key);
	}

}
